package 笔试强训;

import javax.imageio.stream.ImageInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

public class _0415T2 {

    public ArrayList<Integer> intersection(ArrayList<Integer> nums1, ArrayList<Integer> nums2) {
        ArrayList<Integer> res = new ArrayList<>();
        HashMap<Integer, Integer> map = new HashMap<>();
        int minSize = Math.min(nums1.size(), nums2.size());
        int i = 0;
        while (i != minSize) {
            int x1 = nums1.get(i);
            map.put(x1, map.getOrDefault(x1, 0) + 1);
            int x2 = nums2.get(i);
            int times = map.get(x2);
            if (times != 0) {
                map.put(x2, times - 1);
                res.add(x2);
                i++;
            }
            if (i == nums1.size()) {

            } else {

            }
            return res;
        }
        return res;
    }

    public static void main(String[] args) {

    }
}
    /*public  ArrayList<Integer> intersection (ArrayList<Integer> nums1, ArrayList<Integer> nums2) {
        ArrayList<Integer> res = new ArrayList<>();
        HashSet<Integer> set = new HashSet<>();
        int len1 = nums1.size();
        int len2 = nums2.size();
        for (int i = 0; i < len1; i++) {
            int num1 = nums1.get(i);
            set.add(num1);
            int num2 = nums2.get(i);
            if (set.contains(num2)) {
                res.add(num2);
                set.remove(num2);
            }
        }
        return res;
    }*/

